﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL;
using System.Data.Linq;
using System.Data.SqlClient;
using Website.Logger;

namespace UILGestion.Admin.Proveedor
{
    public partial class ProveedorListForm : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {

                try
                {

                    idObra.Value = (string)Request.QueryString["idObra"];
                    menuCtrl1.loadMenuAdmin();
                    FormatForm();


                }
                catch (SqlException sqlex)
                {
                    WebServerSideSqlError.Log(sqlex);
                    //string script;
                    //script = String.Format("<script languaje=\"javascript\">" +
                    //    "alert(" + sqlex + ")"+
                    //          "</script>");
                    //ClientScript.RegisterStartupScript(this.GetType(), "", script);

                }
                catch (Exception ex)
                {
                    WebServerSideError.Log(ex);
                }


            }
        }
        //private void Find()
        //{
        //    dbGestionDataContext _db;

        //    _db =
        //        new dbGestionDataContext(Parametros.strConnString);

        //    //(DD/MM/yyyy)
        //    System.IFormatProvider MiFp =
        //                                                new System.Globalization.
        //                                                CultureInfo("es-ES", false);
        //    //valores de parametro

        //    var q = from i in _db.view_Proveedor
        //            select i;

           
        //    proveedorGridView.DataSource = q;
        //    proveedorGridView.DataBind();
        //}
        private void FormatForm()
        {
            ShowAllComboBox();
            //restricionesForm();
            //Find();
            //estadistica();

            string Lang = "es-ES";  //para controlar el idioma 
            System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo
   (Lang);

            //ImportPresupuestoLinkButton.OnClientClick =
            //    WindowPresupuesto.GetShowReference("../Admin/PresuImportForm.aspx", "Importacion Presupuesto");
        }
        protected void ShowAllComboBox()
        {

            //obraDropDownList.Items.Clear();

            //dbGestionDataContext _db;


            //_db = new dbGestionDataContext(Parametros.strConnString);
            //var q = from r in _db.Obras
            //        select r;
            //List<DAL.Obra> e = q.ToList();
            //DAL.Obra todoItem = new DAL.Obra();
            //todoItem.idInternal = 0;
            //todoItem.descripcion = "------Todos------";
            //e.Add(todoItem);

            //OBRA empleadoMiEquipo = new Employees();
            //empleadoMiEquipo.internalid = 1;
            //empleadoMiEquipo.entityid = "Mi Equipo";
            //e.Add(empleadoMiEquipo);
            ////e.OrderByDescending<Employees>(2);

            //obraDropDownList.DataSource =
            //    e.OrderBy(w => w.idInternal).ToList();
            //obraDropDownList.DataTextField = "descripcion";
            //obraDropDownList.DataValueField = "idInternal";
            //obraDropDownList.DataBind();
            //obraDropDownList.SelectedValue = idObra.Value;

            //OBRADropDownList.SelectedValue = (string)Request.QueryString["empleado_id"];

        }
       
     

        protected void nuevoButton_Click(object sender, EventArgs e)
        {

            Response.Redirect("ProveedorEditForm.aspx?type=A", true);
        }

        protected void obraDropDownList_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {

                //Find();
                //estadistica();
            }
            catch (SqlException sqlex)
            {
                WebServerSideSqlError.Log(sqlex);
                //string script;
                //script = String.Format("<script languaje=\"javascript\">" +
                //    "alert(" + sqlex + ")"+
                //          "</script>");
                //ClientScript.RegisterStartupScript(this.GetType(), "", script);

            }
            catch (Exception ex)
            {
                WebServerSideError.Log(ex);
            }

        }

        protected void fechaInicioDateTime_TextChanged(object sender, EventArgs e)
        {
            try
            {
                //Find();
                //estadistica();
            }
            catch (SqlException sqlex)
            {
                WebServerSideSqlError.Log(sqlex);
                //string script;
                //script = String.Format("<script languaje=\"javascript\">" +
                //    "alert(" + sqlex + ")"+
                //          "</script>");
                //ClientScript.RegisterStartupScript(this.GetType(), "", script);

            }
            catch (Exception ex)
            {
                WebServerSideError.Log(ex);
            }

        }
   
    }
}